import { EventEmitter, Injectable, OnInit } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class CaseReviewService implements OnInit {
  public cloneBizfile: string[] = [];
  public cloneEvidence: string[] = [];

  // 开启视窗事件
  private _newCreateCaseDoc: EventEmitter<any>;
  // 审批视图显示隐藏
  public showWindow = false;
  constructor() {
    this._newCreateCaseDoc = new EventEmitter();
  }
  public getCreateCaseDoc(): EventEmitter<any> {
    return this._newCreateCaseDoc;
  }
  public setShowWindow(flag) {
      this.showWindow = flag;
  }
  public closeWindow(): void {
     this.showWindow = false;
  }

  ngOnInit() {

  }

  setBizfile(bizfile: string[]): void {
    this.cloneBizfile = this.deepClone(bizfile);
  }

  setEvidence(evidence: string[]): void {
    this.cloneEvidence = this.deepClone(evidence);
  }

  // 深度克隆一个数组
  deepClone = (obj) => {
    const clone = Object.assign({}, obj);
    Object.keys(clone).forEach(
      (key) => (clone[key] = typeof obj[key] === 'object' ? this.deepClone(obj[key]) : obj[key]),
    );
    return Array.isArray(obj) && obj.length
      ? (clone.length = obj.length) && Array.from(clone)
      : Array.isArray(obj)
        ? Array.from(obj)
        : clone;
  }
}
